﻿/**  版本信息模板在安装目录下，可自行修改。
* FUJIAN.cs
*
* 功 能： N/A
* 类 名： FUJIAN
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013/7/17 23:05:41   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DQYT.HTDZ.IDAL;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Model;

namespace DQYT.HTDZ.OracleDAL
{
	/// <summary>
	/// 数据访问类:FUJIAN
	/// </summary>
	public partial class FUJIANDAL:IFUJIAN
	{
		public FUJIANDAL()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(decimal ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from FUJIAN");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(FUJIANModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into FUJIAN(");
			strSql.Append("ID,ATTACHID,OBJECTID,OBJECTTYPE,ATTACHNAME,ATTACHURL,ATTACHTYPE,ATTACHBYTES,ATTACHSIZE,UPLOADTIME)");
			strSql.Append(" values (");
            strSql.Append("HTDZ_ID.nextval,:ATTACHID,:OBJECTID,:OBJECTTYPE,:ATTACHNAME,:ATTACHURL,:ATTACHTYPE,:ATTACHBYTES,:ATTACHSIZE,:UPLOADTIME)");
			OracleParameter[] parameters = {
					new OracleParameter(":ATTACHID", OracleType.Number,18),
					new OracleParameter(":OBJECTID", OracleType.Number,18),
					new OracleParameter(":OBJECTTYPE", OracleType.VarChar,30),
					new OracleParameter(":ATTACHNAME", OracleType.VarChar,100),
					new OracleParameter(":ATTACHURL", OracleType.VarChar,200),
					new OracleParameter(":ATTACHTYPE", OracleType.VarChar,30),
					new OracleParameter(":ATTACHBYTES", OracleType.Blob),
					new OracleParameter(":ATTACHSIZE", OracleType.Number,10),
					new OracleParameter(":UPLOADTIME", OracleType.DateTime)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.ATTACHID;
			parameters[2].Value = model.OBJECTID;
			parameters[3].Value = model.OBJECTTYPE;
			parameters[4].Value = model.ATTACHNAME;
			parameters[5].Value = model.ATTACHURL;
			parameters[6].Value = model.ATTACHTYPE;
			parameters[7].Value = model.ATTACHBYTES;
			parameters[8].Value = model.ATTACHSIZE;
			parameters[9].Value = model.UPLOADTIME;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
        public bool Update(FUJIANModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update FUJIAN set ");
			strSql.Append("ATTACHID=:ATTACHID,");
			strSql.Append("OBJECTID=:OBJECTID,");
			strSql.Append("OBJECTTYPE=:OBJECTTYPE,");
			strSql.Append("ATTACHNAME=:ATTACHNAME,");
			strSql.Append("ATTACHURL=:ATTACHURL,");
			strSql.Append("ATTACHTYPE=:ATTACHTYPE,");
			strSql.Append("ATTACHBYTES=:ATTACHBYTES,");
			strSql.Append("ATTACHSIZE=:ATTACHSIZE,");
			strSql.Append("UPLOADTIME=:UPLOADTIME");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ATTACHID", OracleType.Number,18),
					new OracleParameter(":OBJECTID", OracleType.Number,18),
					new OracleParameter(":OBJECTTYPE", OracleType.VarChar,30),
					new OracleParameter(":ATTACHNAME", OracleType.VarChar,100),
					new OracleParameter(":ATTACHURL", OracleType.VarChar,200),
					new OracleParameter(":ATTACHTYPE", OracleType.VarChar,30),
					new OracleParameter(":ATTACHBYTES", OracleType.Blob),
					new OracleParameter(":ATTACHSIZE", OracleType.Number,10),
					new OracleParameter(":UPLOADTIME", OracleType.DateTime),
					new OracleParameter(":ID", OracleType.Number,18)};
			parameters[0].Value = model.ATTACHID;
			parameters[1].Value = model.OBJECTID;
			parameters[2].Value = model.OBJECTTYPE;
			parameters[3].Value = model.ATTACHNAME;
			parameters[4].Value = model.ATTACHURL;
			parameters[5].Value = model.ATTACHTYPE;
			parameters[6].Value = model.ATTACHBYTES;
			parameters[7].Value = model.ATTACHSIZE;
			parameters[8].Value = model.UPLOADTIME;
			parameters[9].Value = model.ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from FUJIAN ");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from FUJIAN ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public FUJIANModel GetModel(decimal ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,ATTACHID,OBJECTID,OBJECTTYPE,ATTACHNAME,ATTACHURL,ATTACHTYPE,ATTACHBYTES,ATTACHSIZE,UPLOADTIME from FUJIAN ");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

            FUJIANModel model = new FUJIANModel();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public FUJIANModel DataRowToModel(DataRow row)
		{
            FUJIANModel model = new FUJIANModel();
			if (row != null)
			{
				if(row["ID"]!=null && row["ID"].ToString()!="")
				{
					model.ID=decimal.Parse(row["ID"].ToString());
				}
				if(row["ATTACHID"]!=null && row["ATTACHID"].ToString()!="")
				{
					model.ATTACHID=decimal.Parse(row["ATTACHID"].ToString());
				}
				if(row["OBJECTID"]!=null && row["OBJECTID"].ToString()!="")
				{
					model.OBJECTID=decimal.Parse(row["OBJECTID"].ToString());
				}
				if(row["OBJECTTYPE"]!=null)
				{
					model.OBJECTTYPE=row["OBJECTTYPE"].ToString();
				}
				if(row["ATTACHNAME"]!=null)
				{
					model.ATTACHNAME=row["ATTACHNAME"].ToString();
				}
				if(row["ATTACHURL"]!=null)
				{
					model.ATTACHURL=row["ATTACHURL"].ToString();
				}
				if(row["ATTACHTYPE"]!=null)
				{
					model.ATTACHTYPE=row["ATTACHTYPE"].ToString();
				}
				if(row["ATTACHBYTES"]!=null && row["ATTACHBYTES"].ToString()!="")
				{
					model.ATTACHBYTES=(byte[])row["ATTACHBYTES"];
				}
				if(row["ATTACHSIZE"]!=null && row["ATTACHSIZE"].ToString()!="")
				{
					model.ATTACHSIZE=decimal.Parse(row["ATTACHSIZE"].ToString());
				}
				if(row["UPLOADTIME"]!=null && row["UPLOADTIME"].ToString()!="")
				{
					model.UPLOADTIME=DateTime.Parse(row["UPLOADTIME"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,ATTACHID,OBJECTID,OBJECTTYPE,ATTACHNAME,ATTACHURL,ATTACHTYPE,ATTACHBYTES,ATTACHSIZE,UPLOADTIME ");
			strSql.Append(" FROM FUJIAN ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM FUJIAN ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from FUJIAN T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "FUJIAN";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

